package com.lywz.web.action.admin.city;

import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import com.lywz.biz.common.entity.city.CityInfo;
import com.lywz.biz.common.entity.city.CityTourismOrganization;
import com.lywz.biz.common.entity.city.CityTraffic;
import com.lywz.biz.common.enums.City;
import com.lywz.core.exception.SSException;
import com.lywz.core.fileUpload.UploadFile;
import com.lywz.web.struts.GZAbstracterAction;

public class BasicInfoAction extends GZAbstracterAction {

    /************************* 常量 ***************************/
    final String CITY_BASIC = "basic";



    private static final long serialVersionUID = -1215000009669109935L;

    private Collection<CityInfo> cityInfoList;

    private CityInfo cityInfo;

    //数据库中自增产生的id
    private short id;

    //获得没有添加的其他城市的名称及id
    private Collection<City> otherCityList;

    //单个城市ID
    private Short cityId;

    //城市基本信息列表
    public String showBasicInfoList() {
        cityInfoList = cityInfoService.getCityInfo();
        return SUCCESS;
    }

    //单个城市信息
    public String showOneCityBasicInfo() {
        cityInfo = cityInfoService.getOneCityById(id);
        return SUCCESS;
    }

    //跳转至添加城市页面
    public String toAddBasicInfo() {
        otherCityList = cityInfoService.getUnaddedCity(CITY_BASIC);
        return "toAdd";
    }

    private File imageUrl;

    private String imageUrlFileName;

    //添加城市基本信息
    public String addBasicInfo() {
        cityInfoService.addCityBasicInfo(cityInfo);
        return SUCCESS;
    }

    //跳转至编辑城市基本信息页面
    public String toModifyBasicInfo() {
        cityInfo = cityInfoService.getOneCityById(id);
        return "toModify";
    }

    //编辑城市基本信息
    public String modifyBasicInfo() {
        
        UploadFile files = new UploadFile(imageUrl, "city/", imageUrlFileName, 50, 50, request);
      /*  files.setFile(imageUrl);
        files.setPath("upload/city/");
        files.setFormate("jpg");
        files.setBasePath("D:/apache-tomcat-6.0.26/webapps/GZLY/resource/");
        files.setHeight(50);
        files.setWidth(50);*/
        List<String> list = Collections.emptyList();
        try {
            list = defaultFileUpload.uploadFile(files);
        } catch (SSException e) {
            e.printStackTrace();
        }        
        
        System.out.println(list.get(0));
        cityInfo.setImageUrl(list.get(0));
        cityInfoService.modifyCityBasicInfo(cityInfo);
        return SUCCESS;
    }

    /*************************** 交通信息 **********************************/


    /*********************** 旅游机构 ***************************************/
    private Collection<City> cityItems;

    private Integer tourismOrgId;

    //市内外旅游机构列表
    private Collection<CityTourismOrganization> cityInsideTourismOrgList;

    private Collection<CityTourismOrganization> cityOutsideTourismOrgList;

    //机构列表
    private CityTourismOrganization tourismOrg;

    //显示所哟城市的旅游机构列表
    public String showCityTourismOrgListAll() {
        cityItems = City.getCityList();
        return SUCCESS;
    }

    public String showCityTourismOrgList() {
        cityInsideTourismOrgList = cityInfoService.getCityTourismOrgListByCityId(cityId, true);
        cityOutsideTourismOrgList = cityInfoService.getCityTourismOrgListByCityId(cityId, false);
        return SUCCESS;
    }

    public String showAddCityTourismOrg() {
        cityItems = City.getCityList();
        return SUCCESS;
    }

    public String addCityTourismOrg() {
        cityInfoService.addTourismOrg(tourismOrg);
        return "tourismSuccess";
    }

    public void ajaxDeleteTourismOrg() {
        cityInfoService.deleteTourismOrgById(tourismOrgId);
    }

    public void ajaxModifyTourismOrg() {
        cityInfoService.modifyTourismOrg(tourismOrg);
    }

    /********************** setter getter *****************************/

    public Collection<CityInfo> getCityInfoList() {
        return cityInfoList;
    }

    public void setImageUrlFileName(String imageUrlFileName) {
        this.imageUrlFileName = imageUrlFileName;
    }

    public void setCityInfoList(Collection<CityInfo> cityInfoList) {
        this.cityInfoList = cityInfoList;
    }

    public CityInfo getCityInfo() {
        return cityInfo;
    }


    public void setCityInfo(CityInfo cityInfo) {
        this.cityInfo = cityInfo;
    }

    public Short getCityId() {
        return cityId;
    }

    public void setCityId(Short cityId) {
        this.cityId = cityId;
    }

    public Collection<City> getOtherCityList() {
        return otherCityList;
    }

    public void setOtherCityList(Collection<City> otherCityList) {
        this.otherCityList = otherCityList;
    }

    public short getId() {
        return id;
    }

    public void setId(short id) {
        this.id = id;
    }


    public Collection<City> getCityItems() {
        return cityItems;
    }

    public void setCityItems(Collection<City> cityItems) {
        this.cityItems = cityItems;
    }

    public Collection<CityTourismOrganization> getCityInsideTourismOrgList() {
        return cityInsideTourismOrgList;
    }

    public void setCityInsideTourismOrgList(
            Collection<CityTourismOrganization> cityInsideTourismOrgList) {
        this.cityInsideTourismOrgList = cityInsideTourismOrgList;
    }

    public Collection<CityTourismOrganization> getCityOutsideTourismOrgList() {
        return cityOutsideTourismOrgList;
    }

    public void setCityOutsideTourismOrgList(
            Collection<CityTourismOrganization> cityOutsideTourismOrgList) {
        this.cityOutsideTourismOrgList = cityOutsideTourismOrgList;
    }

    public CityTourismOrganization getTourismOrg() {
        return tourismOrg;
    }

    public void setTourismOrg(CityTourismOrganization tourismOrg) {
        this.tourismOrg = tourismOrg;
    }

    public Integer getTourismOrgId() {
        return tourismOrgId;
    }

    public void setTourismOrgId(Integer tourismOrgId) {
        this.tourismOrgId = tourismOrgId;
    }

    public File getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(File imageUrl) {
        this.imageUrl = imageUrl;
    }
}
